package com.linux.huhx.source;

import com.linux.huhx.base.BaseSource;
import com.linux.huhx.base.interfaces.IBaseSource;
import com.linux.huhx.base.interfaces.IBaseSourceParse;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by huhx on 2017-06-15.
 */
public class ConsoleSource extends BaseSource<String> {
    private IBaseSourceParse baseSourceParse;

    public IBaseSourceParse getBaseSourceParse() {
        return baseSourceParse;
    }

    public void setBaseSourceParse(IBaseSourceParse baseSourceParse) {
        this.baseSourceParse = baseSourceParse;
    }

    @Override
    public List<String> getStringsFromSource(String split) {
        Scanner scanner = new Scanner(System.in);
        List<String> lines = new ArrayList<>();
        String line = null;
        while (!"end".equals(line = scanner.nextLine())) {
            lines.add(line);
        }
        scanner.close();
        return baseSourceParse.doSourceParse(lines);
    }
}
